#!/usr/bin/perl
# use Data::Dumper;
no warnings 'experimental::smartmatch';
# 该命令一次性列出制定Motor的状态值。如果希望以观察的模式，建议结合watch命令

%MOTOR_PATH;  # Motor Mapping  "A" => "Dirver Path"

getMotorInfo();
foreach $motorName (sort keys %MOTOR_PATH){
	if($#ARGV>=0){
		next unless lc($motorName) ~~ @ARGV;
	}
	$MName=$motorName;
	`echo reset > $MOTOR_PATH{$motorName}/command`;
}
	
#  获得Motor Mapping
sub getMotorInfo{
	for($i=0;$i<5;$i++){
		my $add="/sys/class/tacho-motor/motor$i/address";
		if(-e $add){
			my $content=`cat $add`;
			(my $port)=$content=~/out((A|B|C|D))/;
			$MOTOR_PATH{$port}="/sys/class/tacho-motor/motor$i";
		}
	}
}

